﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Chinaer.WCF.Services;

namespace Chinaer.UI.MVC.Controllers
{
    public class CityController : Controller
    {
        //
        // GET: /City/

        public ActionResult Index()
        {
            return View();
        }

        public ContentResult GetCityByProvinceID(string id)
        {
            ChinaerService chinaService = new ChinaerService();
            List<DTO.CityDTO> listCity = chinaService.GetCityByProvinceID(id, "");
            return new ContentResult() { Content = Helper.JsonHelper.GetJson(listCity, listCity.Count) };
        }
        [HttpPost]
        public ContentResult GetAllCitiesByProvinceID(string id)
        {
            ChinaerService chinaService = new ChinaerService();
            List<DTO.CityDTO> listCity = chinaService.GetCityByProvinceID(id, "");
            return new ContentResult() { Content = Helper.JsonHelper.CreateJson(listCity) };
        }
        [HttpPost]
        public string SaveCity(DTO.CityDTO cityDTO)
        {
            ChinaerService chinaService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaService.AddCity(cityDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        [HttpPost]
        public string UpdateCity(DTO.CityDTO cityDTO)
        {
            ChinaerService chinaService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaService.UpdateCity(cityDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        [HttpPost]
        public string DeleteCity(string ID)
        {
            ChinaerService chinaService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaService.DeleteCityByID(ID, "");
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
    }
}
